package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.Checkitem;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.vo.CheckitemQuery;
import com.atguigu.eduservice.entity.vo.CheckitemVO;
import com.atguigu.eduservice.entity.vo.CourseQuery;
import com.atguigu.eduservice.service.CheckitemService;
import com.atguigu.eduservice.service.EduCourseService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-07-28
 */

@RequestMapping("/eduservice/checkitem")
@RestController
@Api(description="体检管理")
@CrossOrigin
public class CheckitemController {
    @Autowired
    private CheckitemService checkitemService;

    @PostMapping("pageCheckitemCondition/{current}/{limit}")
    public
    R pageCourseCondition(@PathVariable long current, @PathVariable long limit,
                          @RequestBody(required = false) CheckitemQuery checkitemQuery) {
        //创建page对象
        Page<CheckitemVO> pageCourse = new Page<>(current,limit);

        //构建条件
        QueryWrapper<Checkitem> wrapper = new QueryWrapper<>();
        // 多条件组合查询
        // mybatis学过 动态sql
        String title = checkitemQuery.getCheckgroup_name();
        String Status = checkitemQuery.getCheckitem_name();

        //判断条件值是否为空，如果不为空拼接条件
//        System.out.println(title+""+Status);
        if(!StringUtils.isEmpty(title)) {
            //构建条件
            wrapper.like("Checkgroup_name",title);
        }
        if(!StringUtils.isEmpty(Status)) {
            wrapper.eq("Checkitem_name",Status);
        }
//        if(!StringUtils.isEmpty(begin)) {
//            wrapper.ge("gmt_create",begin);
//        }
//        if(!StringUtils.isEmpty(end)) {
//            wrapper.le("gmt_create",end);
//        }

        //排序
        //wrapper.orderByDesc("gmt_create");

        //调用方法实现条件查询分页
        List<CheckitemVO> records=checkitemService.getCheckitemList(pageCourse,checkitemQuery);
        System.out.println(records);

        long total = pageCourse.getTotal();//总记录数
//        List<CheckitemVO> records = pageCourse.getRecords(); //数据list集合
        return R.ok().data("total",total).data("rows",records);
    }

}

